Newer
Older
taehui / taehui-fe / src / app / [language] / components / HitView.tsx
@Taehui Taehui on 17 Mar 838 bytes 2024-03-17 오후 2:12
import useGetHit from "@/app/[language]/query/useGetHit";
import usePostHit from "@/app/[language]/query/usePostHit";
import { HitViewLoading } from "@/components/Loading";
import { useTranslations } from "next-intl";
import { useEffect } from "react";

export default function HitView() {
  const t = useTranslations();

  const {
    data: [hitBefore, hit],
    isFetched: isHitLoaded,
  } = useGetHit();

  const { mutateAsync: postHit } = usePostHit();

  useEffect(() => {
    (async () => {
      await postHit();
    })();
  }, [postHit]);

  return (
    <>
      <h5>{t("hit00")}</h5>
      {isHitLoaded ? (
        <span>
          {t("hit01", { hitBefore })}
          <br />
          {t("hit02", { hit })}
          <br />
          {t("hit03")}
        </span>
      ) : (
        <HitViewLoading />
      )}
    </>
  );
}